package net.techwatch.gwt.xml.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class GwtXmlServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doJob(req, resp);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doJob(req, resp);
	}
	
	private void doJob(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		StringBuilder builder = new StringBuilder("<PERSON>");
		builder.append("<FIRSTNAME>");
		builder.append(req.getParameter("firstName"));
		builder.append("</FIRSTNAME>");
		builder.append("<LASTNAME>");
		builder.append(req.getParameter("lastName"));
		builder.append("</LASTNAME>");
		builder.append("</PERSON>");
		
		ServletOutputStream stream = resp.getOutputStream();
		stream.write(builder.toString().getBytes());
		stream.flush();
	}

}
